using DA.AnimGraph;
using System;
using System.Collections.Generic;

namespace DA.AnimGraph.Editor {

    internal class HandleManager {
        Dictionary<AUID, AGAHandleBase> handles;

        internal HandleManager() {
            handles = new Dictionary<AUID, AGAHandleBase>(10);
        }

        internal void AddHandle(AGAHandleBase handle) {
            handles.Add(handle.uuid, handle);
        }

        internal AGAHandleBase GetHandle(AUID uuid) {
            if (handles.TryGetValue(uuid, out AGAHandleBase handle)) {
                return handle;
            }
            return null;
        }

        internal bool RemoveHandle(AUID uuid) {
            var handle = GetHandle(uuid);
            handle.Destroy();
            return handles.Remove(uuid);
        }


        //
        internal event Action<bool> OnDirtyChange;
        internal bool dirty { get; private set; }

        internal void SetDirty() {
            if (!dirty) {
                dirty = true;
                OnDirtyChange?.Invoke(dirty);
            }
        }

        internal void OnSave() {
            if (dirty) {
                dirty = false;
                OnDirtyChange?.Invoke(dirty);
            }
        }


    }
}
